import os
import datetime
import tensorflow as tf


# 硬件配置
def configure_hardware():
    gpus = tf.config.list_physical_devices('GPU')
    for gpu in gpus:
        tf.config.experimental.set_memory_growth(gpu, True)
    print(f"Available GPUs: {gpus}")
    print(f"Available CPUs: {os.cpu_count()}")
    

class DynamicConfig:
    def __init__(self):
        # 路径配置
        self.cwd = os.getcwd()
        self.pardir = os.path.dirname(self.cwd)
        
        # 动态参数
        self._sunny_dates = []
        self._cloudy_dates = []
        
        # 其他固定参数
        self.file_paths = [
        './data/data_forecast/all/forecast_dataset.hdf5',
        './data/data_forecast/sunny/forecast_dataset.hdf5',
        './data/data_forecast/cloudy/forecast_dataset.hdf5']
        self.TEST_DATES = [(2017,6,8),(2017,9,15),(2017,9,20),(2017,10,6),(2017,10,11),(2017,10,22)]
        self.MODEL_SELECT = "LSTM"  # 默认值
        self.WEATHER_SELECT = "ALL" # 默认值
        self.IMG_SIDE_LEN = 64
        self.NUM_LOG_TERM = 16
        self.NUM_COLOR_CHANNEL = 3
        self.BATCH_SIZE = 256
        self.EPOCHS = 400
        self.LEARNING_RATE = 3e-4
        self.VAL_RATIO = 0.2

    @property
    def data_folder(self):
        """根据当前 WEATHER_SELECT 动态生成 data_folder 路径"""
        weather_subdir = self.WEATHER_SELECT.lower()
        return os.path.join(self.pardir, "solar", "data", "data_forecast", weather_subdir)

    @property
    def output_folder(self):
        """根据当前 WEATHER_SELECT 动态生成 output_folder 路径"""
        weather_subdir = self.WEATHER_SELECT.lower()
        return os.path.join(self.pardir, "solar", "data", "model_output", 'SUNSET_forecast_2017_2019_data', weather_subdir)

    @property
    def SUNNY_DATES(self):
        return self._sunny_dates

    @SUNNY_DATES.setter
    def SUNNY_DATES(self, value):
        self._sunny_dates = value

    @property
    def CLOUDY_DATES(self):
        return self._cloudy_dates

    @CLOUDY_DATES.setter
    def CLOUDY_DATES(self, value):
        self._cloudy_dates = value

# 创建全局配置实例,供整个工程使用
config = DynamicConfig()